function RGBAFilter(arr) {
    arr = arr || [];
    var len = arr.length, i;
    if (len < 16) {
        for (i = len; i < 16; i++) {
            if (i % 5 == 0) {
                arr[i] = 1;
            } else { arr[i] = 0; }
        }
    }
    this.filter = arr;
}
RGBAFilter.prototype = new ImageFilter();
RGBAFilter.prototype.PerformFilter = function (context, dims) {
    var idata, data, len, r, g, b, a, filter = this.filter;
    try {
        dims = dims || {};
        idata = context.getImageData(dims.sx || 0, dims.sy || 0, dims.sw || 0, dims.sh || 0);
        data = idata.data;
        len = data.length;
        for (var i = 0; i < len; i += 4) {
            r = data[i] * filter[0] + data[i + 1] * filter[1] + data[i + 2] * filter[2] + data[i + 3] * filter[3];
            g = data[i] * filter[4] + data[i + 1] * filter[5] + data[i + 2] * filter[6] + data[i + 3] * filter[7];
            b = data[i] * filter[8] + data[i + 1] * filter[9] + data[i + 2] * filter[10] + data[i + 3] * filter[11];
            a = data[i] * filter[12] + data[i + 1] * filter[13] + data[i + 2] * filter[14] + data[i + 3] * filter[15];
            data[i] = r;
            data[i + 1] = g;
            data[i + 2] = b;
            data[i + 3] = a;
        }
        context.putImageData(idata, 0, 0);
    } catch (e) { console.error(e); }
}
RGBAFilter.prototype.PerformFilterEval = function (context, dims) {
    var idata, data, len, r, g, b, a, filter = this.filter, str, i;
    try {
        dims = dims || {};
        idata = context.getImageData(dims.sx || 0, dims.sy || 0, dims.sw || 0, dims.sh || 0);
        data = idata.data;
        len = data.length;
        str = "for(i=0;i<len;i+=4){r="
         + (filter[0] ? "data[i]*" + filter[0] : "0")
         + (filter[1] ? "+data[i+1]*" + filter[1] : "")
         + (filter[2] ? "+data[i+2]*" + filter[2] : "")
         + (filter[3] ? "+data[i+3]*" + filter[3] : "")
         + ";g="
         + (filter[4] ? "data[i]*" + filter[4] : "0")
         + (filter[5] ? "+data[i+1]*" + filter[5] : "")
         + (filter[6] ? "+data[i+2]*" + filter[6] : "")
         + (filter[7] ? "+data[i+3]*" + filter[7] : "")
         + ";b="
         + (filter[8] ? "data[i]*" + filter[8] : "0")
         + (filter[9] ? "+data[i+1]*" + filter[9] : "")
         + (filter[10] ? "+data[i+2]*" + filter[10] : "")
         + (filter[11] ? "+data[i+3]*" + filter[11] : "")
         + ";a="
         + (filter[12] ? "data[i]*" + filter[12] : "0")
         + (filter[13] ? "+data[i+1]*" + filter[13] : "")
         + (filter[14] ? "+data[i+2]*" + filter[14] : "")
         + (filter[15] ? "+data[i+3]*" + filter[15] : "")
         + ";data[i]=r;data[i+1]=g;data[i+2]=b;data[i+3]=a}";
        eval(str);
        context.putImageData(idata, 0, 0);
    } catch (e) { }
}